<?php

$page_title = "Official Shops";
$rank_check = 1;
include "header.inc.php";

$findShops = mysql_query("SELECT id,shop_name,premium_only,shop_greeting,shop_keeper FROM official_shops2 WHERE game = '$game' ORDER BY rand()");
$numShops = mysql_num_rows($findShops);

$x = 0;
while ($getShops = mysql_fetch_array($findShops))
{
	$id = $getShops[id];

	if ($getShops[premium_only] == 1)
	{
		$premiumLock[$id] = "<p align=center><b>Only accessable to premium members.</b></p>";
	}

	if (file_exists("$rootPath/images/user_images/opg_$game/shopkeepers/keeper_$id.gif"))
	{
		if ($x == 0)
		{
			$showKeeperLeft[$id] = "<td width=200><p align=center><img src=images/user_images/opg_$game/shopkeepers/keeper_$id.gif></p></td><td>";
			$x = 2;
		}
		if ($x == 1)
		{
			$showKeeperRight[$id] = "<td width=200><p align=center><img src=images/user_images/opg_$game/shopkeepers/keeper_$id.gif></p></td>";
			$showKeeperLeft[$id]  = "<td>";
			$x = 0;
		}
		if ($x == 2) { $x = 1; }
	}
	else
	{
		$showKeeperLeft[$id] = "<td colspan=2>";
	}

	$shopsList .= "
	<tr width=100%>
	$showKeeperLeft[$id]
	<p align=center><a href=shopping.php?game=$game&shop_id=$getShops[id]><font size=+3>$getShops[shop_name]</font></a></p>

	<p align=center><b>$getShops[shop_keeper]</b> says \"$getShops[shop_greeting]\"</p>

	$premiumLock[$id]

	</td>$showKeeperRight[$id]</tr>
	<tr><td colspan=2><hr width=90% color=\"$tableOutline\"></td></tr>
	";
}

$shopsList = "<table cellspacing=1 cellpadding=0 width=95% bgcolor=$tableOutline><tr bgcolor=#FFFFFF><td><table cellspacing=0 cellpadding=0 width=100% bgcolor=#FFFFFF>$shopsList</table></td></tr></table>";

if ($numShops == 0)
{
	if ($rank == 7)
	{
		$adminLine2 = "&#91;Admins: Click <a 	href=admin/admin_add_shop.php?game=$game>here</a> to add official shops!&#93;";
	}
}

print "$openHTML$adminLine2";

$findPage = fetch("SELECT * FROM game_pages WHERE page_title = '$page_title' AND game = '$game'");
if (!$findPage[id])
{

ECHO <<<END

<br><br><b><font face="Arial" size="2" color="#FF0000">Welcome to Items Mall ! Here you can find various shops selling different powerful items, magic drink and foods. Enjoy your shopping.</font></b><br><br>

END;

}
else
{
	include "showpage.inc.php";
	print "$findPage[page_info]";
}

ECHO <<<HTML

<CENTER>

$shopsList

</CENTER>

$closeHTML

HTML;

?>